<template>
	<view class="content">
		<QSInput layout="column" :tapClear=false :name="formName" variableName="type"  title="链接类型" v-model="type" :itemDisabled="true"></QSInput>
		<QSInput layout="column" :name="formName" variableName="ewallet"  title="钱包地址" v-model="values.ewallet" :itemDisabled="itemDisabled">dfasdfas</QSInput>
		<QSInput layout="column" :name="formName" variableName="phone"  title="手机号码" ifCode v-model="values.phone" :itemDisabled="itemDisabled" @getCode="getCode">dfasdfas</QSInput>
		<QSInput layout="column" :name="formName" variableName="smscode"  title="验证码" v-model="values.smscode" :itemDisabled="itemDisabled">dfasdfas</QSInput>
		<QSInput layout="column" :name="formName" variableName="account"  title="帐号" v-model="values.account" :itemDisabled="itemDisabled">dfasdfas</QSInput>
		<QSInput layout="column" :name="formName" variableName="name"  title="名称" v-model="values.name" :itemDisabled="itemDisabled">dfasdfas</QSInput>
		<QSInput layout="column" :name="formName" variableName="bank"  title="开户行" v-model="values.bank" :itemDisabled="itemDisabled">dfasdfas</QSInput>
		<button type="primary" @tap="bangding">绑定</button>
	</view>
</template>

<script>
	
	export default {
		components: {
			
		},
		data() {
			return {
				formName: 'input',
				link:'',
				itemDisabled: false,
				type:'',
				values:{},
				id:0,
				token:'',
				phone:''
			}
		},
		onLoad(option) {
			var  that=this;
			that.type = option.type;
			that.id = option.id;  //如果id 为null 新增 否则是修改
		},
		onShow(){
			this.checkToken();
		},
	
		methods: {
			getCode () {
				
			},
			checkToken(){
				var that=this;
				 uni.getStorage({
				    key: 'token',
				    success: function (res) {
						that.token=res.data;
						that.getAccount(res.data);
				    },
					fail:function(error){
						uni.navigateTo({
							url: `/pages/login/login`
						})
					}});
			},
			//如果id有，先查用户的帐户信息
			getAccount(token){
				var that=this;
				if(that.id!=0){
				var that=this;
				uni.request({
						url: that.serverUrl + '/core/api/v1/hy/payment/'+that.id,
						method: "GET",
						header: {
							'content-type': 'application/json',
							'Authorization': 'Bearer '+that.token
						},
						success: (res) => {
							if (res.data.code == 200) {
								console.log(res.data.data);
								that.values=res.data.data;
							}
						},
						fail: (error) => {
							console.log(error);
						}
					})
				}
			},
			
			//绑定提交
			bangding(){
				var that=this;
				console.log(that.values);
				var url="";
				console.log(that.token);
				if(that.id==0) //新增/core/api/v1/hy/payment
				{
					that.$set(that.values,'type',that.type);
					uni.request({
								url: that.serverUrl + '/core/api/v1/hy/payment',
								method: "POST",
								data:that.values,
								header: {
									'content-type': 'application/json',
									'Authorization': 'Bearer '+that.token
								},
								success: (res) => {
									if (res.data.code == 200) {
										console.log(res.data.data);
									}
								},
								fail: (error) => {
									console.log(error);
								}
							})
					
				}
				else  //修改 /core/api/v1/hy/payment/{id}
				{
					
					uni.request({
								url: that.serverUrl + '/core/api/v1/hy/payment/'+that.id,
								method: "PUT",
								data:that.values,
								header: {
									'content-type': 'application/json',
									'Authorization': 'Bearer '+that.token
								},
								success: (res) => {
									if (res.data.code == 200) {
										console.log(res.data.data);
									}
								},
								fail: (error) => {
									console.log(error);
								}
							})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	$color-primary: #12B3F9;
	.content {
		display: flex;
		flex-direction: column;
		// align-items: center;
		// justify-content: center;
		// background-color: #F2F2F2;
	}
	
	button[type="primary"]{
		background-color: $color-primary;
		border-radius: 0;
		font-size: 34upx;
		margin-top: 60upx;
		width: 80%;
		border-radius: 40upx;
	}
</style>
